// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <nebula/types/type_holder.h>

namespace nebula {

    // ----------------------------------------------------------------------
    // TypeHolder

    std::string TypeHolder::to_string(const std::vector<TypeHolder> &types,
                                      bool show_metadata) {
        std::stringstream ss;
        ss << "(";
        for (size_t i = 0; i < types.size(); ++i) {
            if (i > 0) {
                ss << ", ";
            }
            ss << types[i].type->to_string(show_metadata);
        }
        ss << ")";
        return ss.str();
    }

    std::vector<TypeHolder> TypeHolder::FromTypes(
            const std::vector<std::shared_ptr<DataType>> &types) {
        std::vector<TypeHolder> type_holders;
        type_holders.reserve(types.size());
        for (const auto &type: types) {
            type_holders.emplace_back(type);
        }
        return type_holders;
    }

    std::ostream &operator<<(std::ostream &os, const TypeHolder &type) {
        os << type.to_string();
        return os;
    }

}  // namespace nebula
